﻿using Essential.Diagnostics;
using System;
using System.Diagnostics;

namespace RockBus.Logging.Trace
{
    public class DebugTraceListener : TraceListenerBase
    {
        private readonly TraceFormatter traceFormatter = new TraceFormatter();

        protected override void WriteTrace(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message, Guid? relatedActivityId, object[] data)
        {
            string message2 = this.traceFormatter.Format(this.Template, this, eventCache, source, eventType, id, message, relatedActivityId, data);
            Debug.WriteLine(message2);
        }

        protected override string[] GetSupportedAttributes()
        {
            return new[] { "template" };
        }

        public string Template
        {
            get
            {
                if (base.Attributes.ContainsKey("template"))
                {
                    return base.Attributes["template"];
                }
                return "{Source} {EventType}: {Id} : {Message}";
            }
            set
            {
                base.Attributes["template"] = value;
            }
        }
    }
}